﻿package lobby.exchangeddata
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import lobby.events.LobbyEvent;
	import lobby.constants.ConstData;
	
	/**
	 * ...
	 * @author Doan Nguyen Thuy Nha Truc (Bamboo)
	 */
	public class HistoryInfoSedie extends HistoryInfoBase
	{
		public function HistoryInfoSedie()
		{
			this.gameTypeIndex = 6;
		}
		
		public override function returnSetHistory(result:String):Array
		{
			
			super.setOdlResult = result;
			
			odlResult = result;
			var resultArr:Array = new Array();
			result = result.substr(38, result.length);
			result = result.substr(0, result.length - 1);
			
			resultArr = result.split(";");
			history = resultArr;
			businessHis(resultArr);
			
			return history;
		}
		
		/**
		 * @author Bamboo
		 * @param resultArr
		 * @usage  prosecute data to draw history. Check the first is even or odd, then check the next history. If col is over max, function recall
		 */
		private function businessHis(resultArr:Array):void
		{
			
			var colInd:uint = 0;
			var rowInd:uint = 0;
			var pos:uint = 0;
			var colNum:uint = 13;
			var rowNum:uint = 6;
			var flagEven:Boolean;
			var flagPos:Boolean = true;
			var flagTemp:Boolean;
			var flagCheckEvenOdd:Boolean;
			var tempHis:Array = new Array();
			tempHis = resultArr[0].split("-");
			if (tempHis[1] % 2 == 0)
			{
				flagEven = true;
			}
			else
			{
				flagEven = false;
			}
			
			for (var i:int = 1; i < resultArr.length; i++)
			{
				tempHis = new Array();
				tempHis = resultArr[i].split("-");
				flagCheckEvenOdd = checkEvenOdd(tempHis[1]);
				if (flagEven)
				{
					if (flagCheckEvenOdd)
					{
						rowInd++;
						flagTemp = true;
					}
					else
					{
						colInd++;
						rowInd = 0;
						flagTemp = false;
					}
				}
				else
				{
					if (flagCheckEvenOdd)
					{
						colInd++;
						rowInd = 0;
						flagTemp = true;
					}
					else
					{
						rowInd++;
						flagTemp = false;
					}
				}
				
				if (rowInd == rowNum)
				{
					colInd++;
					rowInd = 0;
				}
				
				if (colInd == 1 && flagPos)
				{
					pos = i;
					flagPos = false;
				}
				
				flagEven = flagTemp;
				if (colInd == colNum)
				{
					resultArr = resultArr.slice(pos, resultArr.length);
					colInd = 0;
					rowInd = 0;
					pos = 0;
					flagPos = true;
					
					history = resultArr;
					businessHis(resultArr);
					break;
				}
			}
		
		}
		
		private function checkEvenOdd(value:uint):Boolean
		{
			if (value % 2 == 0)
				return true;
			return false;
		}
	}

}